package com.whfc.wxmp.api.emp.controller;

import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.emp.enums.AttendType;
import com.whfc.emp.param.AppEmpInputDataAddParam;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.fuum.entity.WxUser;
import com.whfc.wxmp.api.emp.service.MpEmpInputDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author sun_guodong
 * @description 录入记录
 * @date 2020-08-03
 */
@RestController
@RequestMapping("/mp/api/emp/attend/inputData")
public class WxEmpInputDataController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MpEmpInputDataService mpEmpInputDataService;

    @PostMapping("/add")
    public Result add(@CurrentWxUser WxUser wxUser,
                      @Validated @RequestBody AppEmpInputDataAddParam param) {
        logger.info("手动添加考勤数据,loginer:{},param:{}", wxUser.getId(), param.toString());
        param.setType(AttendType.MP.getValue());
        mpEmpInputDataService.add(param);
        return ResultUtil.success();
    }

    @PostMapping(value = {"/anon/upload", "/upload"})
    public Result upload(@RequestParam("file") MultipartFile file) {
        logger.info("上传打卡照片,file:{}", file.getOriginalFilename());
        OssPathDTO data = mpEmpInputDataService.upload(file);
        return ResultUtil.success(data);
    }
}
